package com.hll.mapper;

import com.hll.pojo.User;
import org.mybatis.spring.SqlSessionTemplate;

import java.util.List;

/**
 * @author: Mr.Hu
 * @create: 2021-03-12 10:35
 */
public class UserMapperImpl implements UserMapper {
  // 原来所有操作都通过SqlSession来执行，现在都是SqlSessionTemplate
  private SqlSessionTemplate sqlSession;

  public void setSqlSession(SqlSessionTemplate sqlSession) {
    this.sqlSession = sqlSession;
  }

  public List<User> getUsers() {
    UserMapper mapper = sqlSession.getMapper(UserMapper.class);
    return mapper.getUsers();
  }

  @Override
  public int addUser(User user) {
    UserMapper mapper = sqlSession.getMapper(UserMapper.class);
    return mapper.addUser(user);
  }

  @Override
  public int deleteUser(int id) {
    UserMapper mapper = sqlSession.getMapper(UserMapper.class);
    return mapper.deleteUser(id);
  }
}
